using System;
using System.Collections.Generic;
using DecisionMaking.Domain;

namespace DecisionMaking.BusinessLogic
{
    /// <summary>
    /// In charge of executing a simulation as a background process, polling that background process as well as reading simulations executed in the past
    /// </summary>
    public interface IExecutionManager
    {
        /// <summary>
        /// Executes the algorithm specified by the simulation on the specified agent and all possible pairs of the specified candidates. 
        /// Simulates the process where an agent (a person) works through a set of candidates and determines the correct one out of each set of two
        /// </summary>
        /// <param name="algorithm"></param>
        /// <param name="agent"></param>
        /// <param name="candidates"></param>
        /// <param name="cues"></param>
        /// <returns></returns>
        AlgorithmExecutionOutcome ExecuteAgent(IAlgorithm algorithm, Agent agent, IList<Candidate> candidates, IList<Cue> cues);

        /// <summary>
        /// Executes the algorithm specified by the definition on the specified environment in the background
        /// </summary>
        /// <param name="algorithmDefinitionId"></param>
        /// <param name="environmentId"></param>
        /// <returns>Id of the simulation to look up within execution context</returns>
        Guid ExecuteEnvironment(int algorithmDefinitionId, int environmentId);

        /// <summary>
        /// Reads the specified simulation outcome from persistent storage
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        SimulationOutcome GetSimulationOutcome(Guid id);

        /// <summary>
        /// Returns a list of all simulation outcomes for the specified account
        /// </summary>
        /// <param name="accountId"></param>
        /// <returns></returns>
        IList<SimulationOutcome> GetSimulationOutcomes(int accountId);

        /// <summary>
        /// Returns the execution progress of the currently executing simulation with the specified id or null if not such simulation
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        double? GetExecutionProgress(Guid id);

        /// <summary>
        /// Retrieves the last exception that occured while performing the execution with the specified id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        AlgorithmExecutionException GetLastException(Guid id);
    }
}